package com.luoshizhen.lease.web.app.controller.history;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luoshizhen.lease.common.login.LoginUserHolder;
import com.luoshizhen.lease.common.result.Result;
import com.luoshizhen.lease.web.app.service.BrowsingHistoryService;
import com.luoshizhen.lease.web.app.vo.history.HistoryItemVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.luoshizhen.lease.web.app.vo.history.HistoryItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "浏览历史管理")
@RequestMapping("/app/history")
public class BrowsingHistoryController {

    @Autowired
    private BrowsingHistoryService service;

    /**
     * 获取用户的浏览历史
     *
     * @param current 当前页码，用于分页查询
     * @param size 每页记录数，用于分页查询
     * @return 返回一个Result对象，其中包含分页的浏览历史项
     */
    @Operation(summary = "获取浏览历史")
    @GetMapping("pageItem")
    private Result<IPage<HistoryItemVo>> page(@RequestParam long current, @RequestParam long size) {
        // 创建一个分页对象，用于存储分页查询的信息
        Page<HistoryItemVo> page = new Page<>(current, size);
        // 调用服务层方法，根据用户ID分页查询浏览历史项
        IPage<HistoryItemVo> result = service.pageHistoryItemByUserId(page, LoginUserHolder.getLoginUser().getUserId());
        // 返回查询结果，封装在Result对象中
        return Result.ok(result);
    }
}
